package org.dreamwork.jasmine2.web.client;

import java.util.regex.Matcher;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-4-26
 * Time: 下午8:38
 */
public class IPhoneParser {
/*
Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3
group[1]=iPhone
group[2]=534.46
group[3]=5.1

Mozilla/5.0 (iPad; CPU OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3
group[1]=iPad
group[2]=534.46
group[3]=5.1
 */
    public static UserAgent parse (Matcher m) {
        UserAgent agent = new UserAgent (m.group (0));
        agent.setType (BrowserType.Safari);

        String type = m.group (1);
        if ("iPad".equalsIgnoreCase (type.trim ()))
            agent.setDevice (DeviceType.IPAD);
        else
            agent.setDevice (DeviceType.IPHONE);

        OperationSystem os = OSParser.parseOS (m.group (0));
        agent.setOs (os);

        Version version = new Version (m.group (2));
        RenderKernel kernel = new RenderKernel (RenderkernelType.AppleWebKit, version);
        agent.setKernel (kernel);

        version = new Version (m.group (3));
        agent.setVersion (version);
        return agent;
    }
}
